<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>配置活动</title>
		<link rel="stylesheet" href="../assistant/css/reset.css" />
        <link rel="stylesheet" href="../assistant/css/platform.css" />
        <link rel="stylesheet" href="../assistant/js/ui/jquery-ui.min.css" />
        <style type="text/css">
        	span.cbox{line-height:26px;display:inline-block;}
        	span.cbox input{margin-top:6px;margin-right:2px;}
        	span.cbox label{text-align:left !important;}
        	.u-multiform .column label{width:100px;}
        </style>
	</head>
	<body>
		<div class="header">
            <div class="u-title">配置活动</div>
        </div>
        <form id="form">
	        <div class="task-manage" >
	            <div class="u-multiform search-param">
	                <div class="column">
	                    <div class="cell">
	                        <label>订单提交时间：</label>
	                        <div class="cnt-box">
	                            <input class="u-ipt ipt-datepicker" type="text" id="starttime" name="orderStartTime" />
	                            <span class="split">-</span>
	                            <input class="u-ipt ipt-datepicker" type="text" id="endtime" name="orderEndTime" />
	                        </div>
	                    </div>
	                </div> 
	                <div class="column">
	                    <div id="orderStatusCell" class="cell">
	                        <label>订单状态：</label>
	                        <div class="cnt-box">
	                        	<span class="cbox">
		                            <input id="os1" type="checkbox" name="orderStatus" value="1">
		                            <label for="os1">订单受理中</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="os2" type="checkbox" name="orderStatus" value="2">
		                            <label for="os2">处理中</label>
	                            </span>
	                             <span class="cbox">
		                            <input id="os3" type="checkbox" name="orderStatus" value="20">
		                            <label for="os3">用户已发货</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="os4" type="checkbox" name="orderStatus" value="3">
		                            <label for="os4">服务完成</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="os5" type="checkbox" name="orderStatus" value="4">
		                            <label for="os5">订单已取消</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="os6" type="checkbox" name="orderStatus" value="40">
		                            <label for="os6">取消中</label>
	                            </span>
	                            </br>
	                            <span class="cbox">
		                            <input id="os7" type="checkbox" name="orderStatus" value="5">
		                            <label for="os7">退货中</label>
	                            </span>
	                        	<span class="cbox">
		                            <input id="os8" type="checkbox" name="orderStatus" value="6">
		                            <label for="os8">退货完成</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="os9" type="checkbox" name="orderStatus" value="7">
		                            <label for="os9">支付完成</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="os10" type="checkbox" name="orderStatus" value="70">
		                            <label for="os10">支付中</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="os11" type="checkbox" name="orderStatus" value="8">
		                            <label for="os11">支付失败</label>
	                            </span>
	                        </div>
	                    </div>
	                </div>    
	                <div class="column">    
	                    <div id="cateTypeCell" class="cell">
	                        <label>品类选择：</label>
	                        <div class="cnt-box">
	                            <span class="cbox">
		                            <input id="ct1" type="checkbox" name="cateType" value="00001">
		                            <label for="ct1">空调</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="ct2" type="checkbox" name="cateType" value="00002">
		                            <label for="ct2">冰洗</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="ct3" type="checkbox" name="cateType" value="00003">
		                            <label for="ct3">黑电</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="ct4" type="checkbox" name="cateType" value="00005">
		                            <label for="ct4">电脑</label>
	                            </span>
	                            <span class="cbox">
		                            <input id="ct5" type="checkbox" name="cateType" value="00006">
		                            <label for="ct5">手机</label>
	                            </span>
	                        </div>
	                    </div>
	                </div>
	            
	            	<button type="button" class="u-btn small" onClick="confirm()">确定</button>
	                <button type="button" class="u-btn gray small btn-close" onClick="back()">取消</button>
	            </div>
	        </div>
        </form>
        <div class="u-popup" id="popup_tips">
        	<div class="bg"></div>
            <div class="asTable">
                <div class="asTableCell">
                    <div class="asCell alert">
                        <a href="javascript:;" class="close btn-close">×</a>
                        <p class="title">提示</p>
                        <div class="container">
                            <div class="error"></div>
                            <p style="max-height: inherit;"></p>
                        </div>
                        <div class="btn-box">
                            <button class="u-btn btn-close">确定</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script src="../assistant/js/jquery.min.js"></script>
        <script src="../assistant/js/ui/jquery-ui.min.js"></script>
        <script src="../assistant/js/ui/jquery-ui-timepicker-addon.js"></script>
        <script src="../assistant/js/platform.js"></script>
        <script src="js/DataInterface.js"></script>
        
        <script type="text/javascript">
        	//实例化时间
    		PLATFORM.datepickerRange("#starttime", "#endtime");
    		
    		function back(){
    			window.history.go(-1);
    		}
			function checkParam(){
				return true; //不做验证
				var starttime = $('#starttime').val();
				var endtime = $('#endtime').val();
				if(!starttime){
					PLATFORM.showTips("error", "订单提交开始时间必须有值");	
					return false;
				}
				if(!endtime){
					PLATFORM.showTips("error", "订单提交结束时间必须有值");	
					return false;
				}
				var orderStatusLen = $('#orderStatusCell input:checked');
				if(orderStatusLen.length == 0){
					PLATFORM.showTips("error", "请选择订单状态");	
					return false;
				}
				var cateTypeLen = $('#cateTypeCell input:checked');
				if(cateTypeLen.length == 0){
					PLATFORM.showTips("error", "请选择品类");	
					return false;
				}
				return true;
			}
    		
			//确定按钮触发时间
    		function confirm(){
    			if(!checkParam()){
					return;
    			}
    			var v = $('#form').serialize();
    			var sessionValue = sessionStorage.getItem('key_exchange');
    			var activity = JSON.parse(sessionValue);
				delete activity.orderStartTime;
				delete activity.orderEndTime;

    			var data = $.param(activity);
				if(v){
					data+='&'+v;
				}				
				data = data.replace(/\+/g,' ')
    			$.ajax({
		            type: "post",
		            dataType: "json",
		            contentType:"application/x-www-form-urlencoded; charset=UTF-8",
		            data:data,
		            url: DI.saveRule,
		            success: function(data) {
		           		sessionStorage.removeItem('key_exchange');
		            	window.location.href = 'couponActivityList.html';
		            }
		        });
    			
    		}
    		
    		$(document).ready(function(){
    			init();
    		})
			function init(){
				var sessionValue = sessionStorage.getItem('key_exchange');
    			var currentActivity = JSON.parse(sessionValue);
    			var activityId = currentActivity.activityId;
    			if(activityId){
    				$.ajax({
			            type: "post",
			            dataType: "json",
			            contentType:"application/x-www-form-urlencoded; charset=UTF-8",
			            data:'activityId='+activityId,
			            url: DI.findActivityById,
			            success: function(data) {
			           		if(data.retFlag == 1){
								var activityObj = data.data;
								fillData(activityObj);
							}else{
								console.log('查询活动失败:'+activityId);
							}
			            }
			        });
    			}	
			}
			
			var osObj = {
					"1" : "os1",
					"2" : "os2",
					"20" : "os3",
					"3" : "os4",
					"4" : "os5",
					"40" : "os6",
					"5" : "os7",
					"6" : "os8",
					"7" : "os9",
					"70" : "os10",
					"8" : "os11"
				}
			var ctObj = {
					"00001" : "ct1",
					"00002" : "ct2",
					"00003" : "ct3",
					"00005" : "ct4",
					"00006" : "ct5"
				}

			function fillData(activityObj){
				var starttime = activityObj.starttime;
				var endtime = activityObj.endtime;
				if(starttime){
					$('#starttime').val(starttime);
				}
				if(endtime){
					$('#endtime').val(endtime);
				}
				var orderStatusList = activityObj.orderStatus;
				var cateTypeList = activityObj.cateType;
				for(var i = 0;i<orderStatusList.length;i++){
					var os = orderStatusList[i];
					var osId = osObj[os];
					$('#'+osId).prop('checked',true);
				}

				for(var i = 0;i<cateTypeList.length;i++){
					var ct = cateTypeList[i];
					var ctId = ctObj[ct];
					$('#'+ctId).prop('checked',true);
				}
			}
        </script>
	</body>
</html>
